<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>通信设备管理</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/datepicker/WdatePicker.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
</head>
<body class="app">
	<h3>通信设备管理</h3>
	<form class="search" name="search">
		<div class="tbdiv">
		<table>
			<tr>
				<th>通信设备号：</th>
				<td><input name="devId" type="text" class="inputText" /></td>
				<th>标记：</th>
				<td><input name="remark" type="text" class="inputText" /></td>
				<th>审核状态：</th>
				<td>
					<select name="checkStatus">
						<option value="">-请选择-</option>
						<option value="0">已发放</option>
						<option value="1">已接收</option>
						<option value="2">已退回</option>
						<option value="3">已关联</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>所属区域：</th>
				<td colspan="4">
					<input type="hidden" name="areaName" value=""/>
					<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
				</td>
				<td align="right"><input type="submit" class="inputButton" value="查询"/></td>
			</tr>
		</table>
		</div>
	</form>
	<div id="list"></div>
	<div class="optionlink">
		<span id="btnAdd">【添加信息】</span>
		<span id="btnDel">【删除所选】</span>
	</div>
	<div id="view" style="width:650px;display:none;">
		<form id="saveForm" name="saveForm" action="txsbgl_save.action" method="post">
		<input type="hidden" name="id" />
		<dl class="view">
			<dt class="giant">设备号：</dt>
			<dd class="giant" id="lh_devId"><input type="text" class="inputText" style="width:150px" name="devId" value="C" ver="/^[cC][0-9a-fA-F]{6,6}$/" msg="您输入的设备号不合法。" onchange="vCode(this)" /></dd>
			<dt class="giant">协议类型：</dt>
			<dd class="giant"><select name="pact" style="width:159px" ver="empty" msg="请选择协议类型。"></select></dd>
			<dt class="giant">所属区域：</dt>
			<dd class="giant">
				<input type="hidden" name="areaName" value="" ver="empty" msg="请选择所属区域。"/>
				<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
			</dd>
			<dt class="giant">所属行政单位：</dt>
			<dd class="giant"><select name="adminCode" ver="empty" msg="请选择所属行政单位。" style="width:159px"></select></dd>
			<dt class="giant">所属机构：</dt>
			<dd class="giant"><select name="agencyType" ver="empty" msg="请选择所属机构。" style="width:159px"></select></dd>
			<dt class="giant">所属单位：</dt>
			<dd class="giant"><select name="unitCode" ver="empty" msg="请选择所属单位。"><option value="">-请选择-</option></select></dd>
			<dt class="giant" style="height:44px;">标记：</dt>
			<dd class="giant" style="height:44px;">
				<p>该标记内容可以作为主要的通信设备筛选条件!</p>
				<p><input type="text" class="inputText" style="width:347px" name="remark" ver="empty" msg="请输入设备编号。" /></p>
			</dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<div class="areaTree"><div id="areaTree" class="ztree"></div></div>
	<script type="text/javascript">
	var vCode = function(obj){
		var ver = $(obj).attr('ver');
		var msg = $(obj).attr('msg');
		var val = $(obj).val();
		var code = ver.substr(1);
			code = code.substr(0,code.length-1);
		var exp = new RegExp(code);
		
		var num = val.substr(1);
		if(num.length < 6){
			var n = 6 - num.length;
			for(i=0;i<n;i++){
				num = '0'+num;
			}
			val = val.substr(0,1)+num;
		}
		
		if($.type(exp) === 'regexp'){
			if(!exp.test(val)){
				$.dialog.alert(msg);
				$(obj).focus();
				$(obj).val('T');
			}else{
				$(obj).val(val.toUpperCase());
			}
		}
	}
	$(function(){
		$(document.search).ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$(document.saveForm).ajaxForm({
			beforeSubmit:function(form){
				var ver = $(document.saveForm).validator();
				if(!ver.reg) $.dialog.alert(ver.msg);
				return ver.reg;
			},
			success:function(response){
				if(response == '1'){
					var param = $(document.search).formParam();
					$('#list').page('param',param);
					$('#list').page('show');
					$.dialog.list['viewdialog'].close();
				}else{
					$.dialog.alert('保存失败，设备号已存在！')
				}
			}
		});
		//分页列表
		$('#list').page({
			url:'txsbgl_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				name:'devId',
				type:'checkbox',
				width:13
			},{
				title:'设备号',
				name:'devId'
			},{
				title:'所属行政监管单位',
				name:'adminName'
			},{
				title:'机构类型',
				name:'agencyTypeText'
			},{
				title:'所属单位',
				name:'agencyType',
				irender:function(row){
					if(row.propertyName!=null){
						return row.propertyName;
					}
					if(row.serviceName!=null){
						return row.serviceName;
					}
				}
			},{
				title:'审核状态',
				name:'checkStatus',
				irender:function(row){
					var text = '';
					switch(row.checkStatus){
						case '0':
							text = '已发放';
							break;
						case '1':
							text = '已接收';
							break;
						case '2':
							text = '已退回';
							break;
					}
					return text;
				}
			},{
				title:'详情',
				render:function(row){
					$a = $('<a href="javascript:void(0)">【详细】</a>');
					$a.click(function(){
						view(row);
					});
					return $a;
				}
			}]
		});
		$('#btnAdd').click(function(){
			view(null);
		});
		$('#btnDel').click(function(){
			$.dialog.confirm('您确认删除所选通信设备吗？',function(){
				var ids = $('#list').data('checked').join(',');
				$.post('txsbgl_del.action',{ids:ids},function(response){
					$('#list').page('show',1);
				});
			});
		});
	});

	$(function(){
		//绑定行政监管单位
		$('select[name=pact]').selectload('../../common/code.action','code','codedesc',{codepid:'53'});
		$('select[name=adminCode]').selectload('../../common/adminunit_select.action','adminCode','adminName');
		$('select[name=agencyType]').selectload('../../common/code.action','code','codedesc',{codepid:'64'});
		
		$('select[name=agencyType]').change(function(){
			switch (this.value) {
				case '2':
					$('select[name=unitCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName');
					break;
				case '3':
					$('select[name=unitCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName');
					break;
				default:
					$('select[name=unitCode]').html('<option value="">-请选择-</option>')
					break;
			}
		});
	})
	
	var view = function(row){
		$('select[name=agencyType] option[value=1]').remove();
		$(document.saveForm).resetForm();
		$(document.saveForm.id).val('');
		$.dialog({
			id:'viewdialog',
			title:'通信设备管理',
			lock:true,
			width:'100%',
			height:'100%',
			padding:'5px 8px 5px 5px',
			content:document.getElementById('view'),
			button:[{
				name:"保存",
				focus:true,
				callback:function(){
					$(document.saveForm).submit();
					return false;
				}
			}],
			close:function(){
				$('input[name=areaNameN]').val('');
				$('input[name=areaName]').val('');
			}
		});
		if(row!=null){
			switch (row.agencyType) {
				case '2':
					row['unitCode'] = row.propertyCode;
					$('select[name=unitCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName',null,false);
					break;
				case '3':
					row['unitCode'] = row.serviceCode;
					$('select[name=unitCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName',null,false);
					break;
				default:
					$('select[name=unitCode]').html('<option value="">-请选择-</option>')
					break;
			}
			$('#lh_devId').html('<label name="devId"></label><input name="devId" type="hidden"/>');
			$.post('../../common/area_name.action',{areacode:row.area},function(data){
				$(document.saveForm.areaNameN).val(data);
			},'text');
			row['areaName'] = row.area;
		}else{
			$('#lh_devId').html('<input type="text" class="inputText" style="width:150px" name="devId" value="T" ver="/^[tT][0-9a-fA-F]{6,6}$/" msg="您输入的设备号不合法。" onchange="vCode(this)" />');
		}
		$(document.saveForm).json2form(row);
	}
	
	
	$(function(){
		$(document).mouseup(function(e){
			var $target = $(e.target);
			if(!$target.is('.areaTree')){
				if($target.parents('.areaTree').length == 0){
					$('.areaTree').hide();
				}
			}
		});
		
		//渲染区域树
		$.fn.zTree.init($('#areaTree'),{
			data: {
				key:{
					name:'areaname'
				},
				simpleData: {
					enable: true,
					idKey:'areacode',
					pIdKey:'parentcode',
					rootPId:0
				}
			},
			async: {
				enable: true,
				url:"../../common/area_tree.action",
				autoParam:["areacode"]
			},
			callback:{
				onClick:function(e,id,node){
					var oldnode = node;
					if(node.isParent == false){
						var $areaTree = $('.areaTree');
						var areaArr = new Array();
						areaArr.unshift(node.areaname);
						while(node.parentcode > 0){
							node = node.getParentNode();
							areaArr.unshift(node.areaname);
						}
						$('input[name=areaNameN]').val(areaArr.join(' > '));
						$('input[name=areaName]').val(oldnode.areacode);
						$areaTree.hide();
					}
				}
			}
		});
		
		//区域树
		$('input[name=areaNameN]').click(function(){
			$this = $(this);
			$hidden = $('input[name=areaName]');
			$areaTree = $('.areaTree');
			$this.val('');
			$hidden.val('');
			var os = $this.offset();
			$areaTree.css({left:os.left,top:os.top+($this.outerHeight(true)-1)});
			$areaTree.show();
		});
	});
	</script>
</body>
</html>
